package com.smw.controller;

import com.smw.pojo.User;
import com.smw.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/login")
    public String login (User user, Model model){
        System.out.println(user);
        try {
            System.out.println("第一步");
            Subject subject = SecurityUtils.getSubject();
            System.out.println("第二步");
            AuthenticationToken token = new UsernamePasswordToken(user.getUserName(), user.getPassWord());
            System.out.println(token+"第三步");
            subject.login(token);
            subject.hasRole("登录");
            return "product";

        }catch (Exception e){
            e.printStackTrace();
            return "loginError";
        }
    }

}
